﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows;
using System.Collections;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Discovery;
using ABB.Robotics.Controllers.RapidDomain;

namespace ABB二次开发
{
    class ABBTask
    {

        ControllerInfo[] controllers;
        Controller controller;

        void ConnectRobot()//连接机器人
        {
            NetworkScanner scanner = new NetworkScanner();
            if (false)
            {
                //连接虚拟
                controllers = scanner.GetControllers(NetworkScannerSearchCriterias.Virtual);
            }
            else
            {
                //连接机器人
                controllers = scanner.GetControllers();
            }
            if (controllers.Length > 0)
            {
                //如果列表不为空 连接第一个
                controller = ControllerFactory.CreateFrom(controllers[0]);
                controller.Logon(UserInfo.DefaultUser);
            }


        }




       //显示程序运行状态
        void RapidExecutionStatusChanged(object sender, ExecutionStatusChangedEventArgs e)
        {
            // this.Invoke(new EventHandler<ExecutionStatusChangedEventArgs>(RapidExecStatusChanged), new object[] { this, e });
            string str = e.Status.ToString();
            if (str == ExecutionStatus.Running.ToString())
            {


            }
            else if (str == ExecutionStatus.Unknown.ToString())
            {

            }
            else
            {

            }
        }

        //显示电机状态
        void StateChanged(object sender, StateChangedEventArgs e)
        {
            //this.Invoke(new EventHandler<StateChangedEventArgs>(StateIsChanged), new Object[] { this, e });
            string str = e.NewState.ToString();

            if (str == ControllerState.MotorsOn.ToString())
            {

            }
            else
            {

            }
        }

        // 显示运行模式状态
        void OperatingModeChanged(object sender, OperatingModeChangeEventArgs e)
        {
            // this.Invoke(new EventHandler<OperatingModeChangeEventArgs>(ModeIsChanged), new Object[] { this, e });
            string str = e.NewMode.ToString();
            if (str == ControllerOperatingMode.Auto.ToString())
            {


            }
            //else if (str == ControllerOperatingMode.AutoChange.ToString())
            //{

            //}
            //else if (str == ControllerOperatingMode.Init.ToString())
            //{

            //}
            //else if (str == ControllerOperatingMode.ManualFullSpeed.ToString())
            //{

            //}
            //else if (str == ControllerOperatingMode.ManualFullSpeedChange.ToString())
            //{

            //}
            //else if (str == ControllerOperatingMode.ManualReducedSpeed.ToString())
            //{

            //}
            else
            {

            }
        }

    }
}
